package com.panshi.api.impl;

import com.panshi.dao.IUserDao;
import com.panshi.api.IUserService;
import com.panshi.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceimpl implements IUserService {

    @Autowired
    IUserDao iUserDao;

    /**
     * 查询所有的用户信息
     * @return
     */
    @Override
    public List<UserVO> findAllUser() {
        return iUserDao.findAllUser();
    }

    /**
     * 新增用户
     * @param userVO
     */
    @Override
    public void addUser(UserVO userVO) {

        iUserDao.addUser(userVO);
    }
    /**
     * 根据邮箱查找用户信息
     * @param email
     * @return
     */
    @Override
    public UserVO findUserByEmail(String email) {

        return iUserDao.findUserByEmail(email);
    }

    /**
     * 根据用户id查询用户信息
     * @param uid
     * @return
     */
    @Override
    public com.panshi.vo.UserVO findUserByuid(String uid) {

        return iUserDao.findUserByuid(uid);
    }

    //修改用户信息
    @Override
    public void updateUserInfo(String uid, String nick, String userDesc, String logo) {
        UserVO userVO = new UserVO();
        userVO.setU_id(Integer.valueOf(uid));
        userVO.setU_name(nick);
        userVO.setU_mark(userDesc);
        userVO.setU_img_url(logo);

        System.out.println("uid  " + uid);

        iUserDao.updateUserInfo(userVO);
    }

    //修改密码
    @Override
    public void updateUserPwd(UserVO userVO) {
        iUserDao.updateUserPwd(userVO);
    }
    //修改密码
    @Override
    public void updateUserEmail(UserVO userVO) {
        iUserDao.updateUserEmail(userVO);
    }

    @Override
    public void updateUserLastTime(UserVO userVO) {
        iUserDao.updateUserLastTime(userVO);
    }

    /**
     * 判断用户账号是否存在
     * @param email
     * @return
     */
    @Override
    public boolean findEmailExist(String email){

        UserVO uservo = findUserByEmail(email);
        if(uservo == null){
            return false;
        }else{
            return true;
        }
    }
    /**
     * 判断账号密码是否匹配
     * @param account
     * @param pwd
     * @return
     */
    @Override
    public boolean checkAccountAndPwd(String account,String pwd){
        UserVO user = findUserByEmail(account);
        if(pwd.equals(user.getU_password())){
            return true;
        }else{
            return false;
        }
    }
}
